﻿<cfsilent>

	<cfset jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice") />

	<cfset teacherArray = arrayNew(1) />
    <cfset rs_teacher=queryNew("tch_id") />
	<cfif event.isArgDefined('Keywords') AND len(event.getArg('Keywords'))>
    
         <cfset sql = "SELECT a.tch_id, a.tch_name, a.tch_sex, t_institute.institute_short 
						FROM t_teacher a 
                             INNER JOIN t_institute ON t_institute.institute_id = a.institute_id  
						WHERE 
							a.tch_id LIKE :keyword 
							OR 
							a.tch_name LIKE :keyword 
						ORDER BY a.tch_name ASC "/>
                        
         <cfset queryObj = new Query( datasource=application.dnsSlave,maxRows=30) />
		 <cfset queryObj.addParam( name="keyword", value=event.getArg('Keywords')&'%', cfsqltype="cf_sql_varchar" )/>
         
         <cfset rs_teacher = queryObj.execute( sql=sql ).getResult()/>
         <cfloop query="rs_teacher" >
         	<cfset arrayAppend(teacherArray,[rs_teacher.tch_id,rs_teacher.tch_name,rs_teacher.tch_sex,rs_teacher.institute_short])/>
         </cfloop>
</cfif>
</cfsilent><cfoutput>#jsonAdvice.encode(data:teacherArray, stringNumbers:true)#</cfoutput>